__license__ = "Public Domain"
__author__ = "Tiago Cogumbreiro

import gtk
import gobject

def get_completion_suffix (text, suffix):
    if text.endswith (suffix):
        return ""

    offset = 1
    len_suffix = len (suffix)
    while offset < len_suffix:
        if text.endswith(suffix[0:offset]):
            return suffix[offset:]

        offset += 1
    
    return suffix

import sys



entry = gtk.Entry()
liststore = gtk.ListStore(gobject.TYPE_STRING)

def on_changed (entry, args):
    liststore, extension = args
    tree_iter = liststore.get_iter_first()
    if tree_iter is not None:
        liststore.remove(tree_iter)
    text = entry.get_text()
    if text != "":
        liststore.append ([text + get_completion_suffix(text, extension)])


completion = gtk.EntryCompletion()
entry.set_completion(completion)
entry.connect("changed", on_changed, (liststore, ".zip"))
completion.set_model(liststore)
completion.set_text_column(0)
completion.set_inline_completion(True)
entry.show()
w = gtk.Window()
w.add (entry)
w.show()
gtk.main()
